<template>
	<div style="height:80vh">
		<div style="display: flex; justify-content: space-between;">
			<h3>教师管理</h3>
			<p></p>
			<h4><button @click="go2Add()">添加新的教师</button></h4>
			<p></p>
		</div>
		<hr>
		<div>
			<div>
				<div style="width: 90% ;">
					<table border="1" style="width: 95%">
						<tbody>
							<tr style="background-color: gainsboro">
								<th>用户编号</th>
								<th>用户名称</th>
								<th>联系方式</th>
								<th>用户头像</th>
								<th>修改</th>
								<th>删除</th>
							</tr>
							<tr v-for="t in teas">
								<td>{{t.uid}}</td>
								<td>{{t.uname}}</td>
								<td>{{t.phone}}</td>
								<td><img v-bind:src="pic(t.pic)" alt="头像" style="width: 5vw;height: 5vw;" /></td>
								<td><button @click="go2Update(t.uid)">修改</button></td>
								<td><button @click="del(t.uid)">删除</button></td>
							</tr>
						</tbody>

					</table>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	export default {
		name: "AdmTeacher",
		data() {
			return {
				tea: {},
				teas: [],
			}
		},
		methods: {

			go2Add() {
				this.$router.push({
					path: "/adm/addtea",
					query: {
						uid: 0,
					}
				})
			},
			go2Update(id) {
				this.$router.push({
					path: "/adm/addtea",
					query: {
						uid: id,
					}
				})
			},
			del(id) {
				let that = this
				console.log("删除老师的id:" + id)
				let url = this.$ip + "/api/adm/tea/del?uid=" + id
				this.$axios.get(url,this.$store.state.user.to)
					.then(function(resp) {
						//打印测试结果
						console.dir(resp.data.data)
						//传输搜索结果
						that.teas = resp.data.data
					})
				console.log(url)
			},
			pic(id) {
				console.log("图片id：" + id)
				let pic = `${this.$ip}/api/public/showimg/` + id;
				if (id == undefined || id == "") {
					pic = "myhead";
				}
				return pic;
			}
		},
		computed: {

		},

		mounted() {
			let that = this
			this.$axios.get(`${this.$ip}/api/adm/tea/findAll`, this.$store.state.user.to)
				.then(function(resp) {
					//打印测试结果
					console.dir(resp.data.data)
					//传输搜索结果
					that.teas = resp.data.data
				})
		}
	}
</script>

<style>
</style>